<?php
/* @var $this ApplesController */
/* @var $dataProvider CActiveDataProvider */

$this->breadcrumbs=array(
	'Apples',
);
if(0==strcmp(Yii::app()->user->name,"admin")){ 
	$this->menu=array(
		array('label'=>'添加测试号码', 'url'=>array('create')),
		array('label'=>'所有号码', 'url'=>array('admin')),
		array('label'=>'在线的号码', 'url'=>array('admin&Apples[stat]=2')),
		array('label'=>'更新统计数据', 'url'=>array('group&save=2')),
		array('label'=>'清理号码', 'url'=>array('check&start=1'),'linkOptions'=>array('class'=>'clean_check'))
	);
}?>
<?php Yii::app()->getClientScript()->registerScriptFile(Yii::app()->baseUrl."/js/Chart.js");?>
<link rel="stylesheet" type="text/css" href="<?php echo Yii::app()->request->baseUrl; ?>/css/map.css" />

<h1>号码池总数据量：<span><?php echo number_format($maxid,0) ?></span>，
	激活量：<span class="activate"><?php echo number_format($nowid,0) ?></span></h1>
 

<DIV id="main">
<DIV id="map">

<?php foreach (Globals::map() as $key => $value) {
	echo '<H1 class=mapl style="MARGIN: '.substr($value,0,strpos($value,' ')).'px 0px 0px '.strstr($value," ").'px"><A href="javascript" class="'.$key.'" rel=\'add\'>'.$key.'</A></H1>'."\n";
} ?>
</DIV>
</DIV>

<script type="text/javascript">
/*<![CDATA[*/
jQuery(function($) {
	// http://www.chartjs.org/docs/
	opt = {};

	var data = {
		labels : [
			<?php foreach ($model as $key => $value) {
				echo '"'.$key.'",';
			} ?>
		],
		datasets : [
			{
				fillColor : "rgba(151,187,205,0.5)",
				strokeColor : "rgba(151,187,205,1)",
				data : [
				<?php foreach ($model as $key => $value) {
					echo $value.', ';
				} ?>
				]
			}
		]
	}
	var ctx = $('#myChart').get(0).getContext('2d');
	//This will get the first returned node in the jQuery collection.
	new Chart(ctx).Bar(data,opt);

<?php 

$things = Globals::map();
$length = count($things);
$weight = 0;
$tempdata = array();
$index = 0;
foreach ($things as $key => $value) {
	$weight += ($length - $index);
	for ($i = 0; $i < ($length - $index); $i++) {
		$tempdata[] = $key;
	}
	$index++;
}
echo "var province = [";
foreach ($tempdata as $key) {
	echo "'".$key."',";
}
echo "];\n";
echo "var weight = ".$weight.";";
?>

function randomShow(){
	var key = parseInt(Math.random()* weight+1);
	AddShow(province[key]);
	var activate = $(".activate").html();
	$(".activate").html(parseInt(activate.replace(/,/g,""))+1);
	setTimeout(randomShow, parseInt(Math.random() * 20) * 100);
}

setTimeout(randomShow, 500);

});
// $use = rand(0, $weight – 1);
// $one = $tempdata[$use];
 
var target  = false,
    tooltip = false,
    title   = false;

function AddShow(cls){ 
    target  = $( '.'+cls );
     
    tooltip = $( '<div class="add"></div>' );
  
    tooltip.css( 'opacity', 0 )
           .html( "" )
           .appendTo( 'body' );

    var init_tooltip = function()
    {
        if( $( window ).width() < tooltip.outerWidth() * 1.5 )
            tooltip.css( 'max-width', $( window ).width() / 2 );
        else
            tooltip.css( 'max-width', 340 );

        var pos_left = target.offset().left + ( target.outerWidth() / 2 ) - ( tooltip.outerWidth() / 2 ),
            pos_top  = target.offset().top - tooltip.outerHeight() - 20;

        if( pos_left < 0 )
        {
            pos_left = target.offset().left + target.outerWidth() / 2 - 20;
            tooltip.addClass( 'left' );
        }
        else
            tooltip.removeClass( 'left' );

        if( pos_left + tooltip.outerWidth() > $( window ).width() )
        {
            pos_left = target.offset().left - tooltip.outerWidth() + target.outerWidth() / 2 + 20;
            tooltip.addClass( 'right' );
        }
        else
            tooltip.removeClass( 'right' );

        if( pos_top < 0 )
        {
            var pos_top  = target.offset().top + target.outerHeight();
            tooltip.addClass( 'top' );
        }
        else
            tooltip.removeClass( 'top' );
			
        tooltip.css( { left: pos_left, top: pos_top + 40 } )
               .animate( { top: '-=20', opacity: 1 }, 500 )
               .animate( { top: '-=20', opacity: 0 }, 500, function()
	            {
	                $( this ).remove();
	            });
    };

    init_tooltip();
};
/*]]>*/
</script>

<canvas id="myChart" width="780" height="300"></canvas>
